package com.laogao.controller;

import com.laogao.utils.AutoFillNameUtils;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author：gaoliang
 * @date： 2025/3/8  12:24
 */
@RestController
@RequestMapping("/auto")
public class TestAutoInsertDistController {
    //http://localhost:8080/auto/list
    @GetMapping("/list")
    public List<Device> list() {
        Device device = new Device();
        List<Device> list = device.getList();
        return list;
    }

    //http://localhost:8080/auto/autoFillList
    @GetMapping("/autoFillList")
    public List<Device> autoFillList() {
        Device device = new Device();
        List<Device> list = device.getList();
        AutoFillNameUtils.setItemNamesForObjectList(list);
        return list;
    }

    //http://localhost:8080/auto/Obj
    @GetMapping("/Obj")
    public Device Obj() {
        Device device = new Device();
        Device list = device.getList().get(0);
        return list;
    }

    //http://localhost:8080/auto/autoFillObj
    @GetMapping("/autoFillObj")
    public Device autoFillObj() {
        Device device = new Device();
        Device list = device.getList().get(0);
        //自动填充
        AutoFillNameUtils.setItemNamesForObject(list);
        return list;
    }

}

@Data
class Device {
    private Long id;
    private String name;
    //字典1
    private Long type1ItemId;
    private String type1ItemName;
    //字典2
    private Long type2ItemId;
    private String type2ItemName;
    //字典3
    private Long type3ItemId;
    private String type3ItemName;
    //字典4
    private Long type4ItemId;
    private String type4ItemName;

    List<Device> getList() {
        List<Device> res = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Device device = new Device();
            device.setId((long) i);
            device.setName("设备:" + "i");
            device.setType1ItemId(1L);
            device.setType2ItemId(2L);
            device.setType3ItemId(3L);
            device.setType4ItemId(4L);
            device.setType1ItemName(null);
            device.setType2ItemName(null);
            device.setType3ItemName(null);
            device.setType4ItemName(null);
            res.add(device);
        }

        return res;
    }
}